package shijian;

import java.util.ArrayList;
import java.util.List;

public class IngredientManagerImpl {
    private List<Ingredient> ingredients;

    public IngredientManagerImpl() {
        ingredients = new ArrayList<>();
    }

    public void addIngredient(Ingredient ingredient) {
        ingredients.add(ingredient);
    }

    public void removeIngredient(String name) {
        ingredients.removeIf(ingredient -> ingredient.getName().equals(name));
    }

    public void updateIngredient(String name, Ingredient updatedIngredient) {
        for (int i = 0; i < ingredients.size(); i++) {
            if (ingredients.get(i).getName().equals(name)) {
                ingredients.set(i, updatedIngredient);
                break;
            }
        }
    }

    public List<Ingredient> getAllIngredients() {
        return ingredients;
    }
}

